package io.lkt.modules.sys.controller;

import io.lkt.common.util.Query;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;
import io.lkt.modules.sys.entity.GzhBrandMapEntity;
import io.lkt.modules.sys.service.GzhBrandMapService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sys/gzhbrandmap")
public class GzhBrandMapController {
    @Autowired
    private GzhBrandMapService gzhBrandMapService;

    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        List<GzhBrandMapEntity> list = gzhBrandMapService.queryPage(query);
        int total = gzhBrandMapService.getListTotal(query).intValue();
        PageUtils page = new PageUtils(list, total, query.getLimit(), query.getPage());
        return R.ok().put("page", page);
    }

    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        gzhBrandMapService.removeById(id);
        return R.ok();
    }

    @RequestMapping("/save")
    public R save(@RequestBody GzhBrandMapEntity entity) {
        if (StringUtils.isEmpty(entity.getGzhCode())) return R.error("请选择公众号");
        if (StringUtils.isBlank(entity.getBrandId().toString())) return R.error("请选择品牌");
        gzhBrandMapService.save(entity);
        return R.ok();
    }
}
